/*
 * @Copyright: 2017 www.yyfax.com Inc. All rights reserved.
 */
package com.yyfax.pay.order.service;

import java.util.HashMap;
import java.util.Map;

import com.yyfax.framework.exception.YYException;
import com.yyfax.pay.common.enums.PayRspCodeEnum;
import com.yyfax.pay.common.enums.PaymentEnum;
import com.yyfax.pay.third.service.ThirdPayService;

/**
 * 第三方服务接口适配器
 * 
 * @author jiangmy
 * @date 2017-04-11 10:37:48
 * @since v1.0.0
 */
public class AdapterService {

	private Map<String, ThirdPayService> adapter = new HashMap<String, ThirdPayService>();

	public void setAdapter(Map<String, ThirdPayService> adapter) {
		this.adapter = adapter;
	}

	/**
	 * 根据渠道适配对应的@ThirdPayService
	 * 
	 * @author jiangmy
	 * @date 2017-04-12 11:54:03
	 * @since v1.0.0
	 * @param channel
	 * @return
	 * @throws YYException 
	 */
	public ThirdPayService adapterPayService(PaymentEnum channel) throws YYException {
		ThirdPayService thirdPayService = adapter.get(channel.getValue());
		if (thirdPayService == null) {
			throw new YYException(PayRspCodeEnum.COMMON_ERROR_OBJECT_NOT_FOUND, "第三方支付通道服务缺失");
		}
		return thirdPayService;
	}
}
